package com.xsz.service;

import java.util.List;
import java.util.Random;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.xsz.entity.User;
import com.xsz.repository.UserRepository;
import com.xsz.util.KeyUtil;

@Service
public class UserService {
	@Resource
	UserRepository userRepository;
	
	public User add(User user) {
		user.setId(KeyUtil.getId());
		return userRepository.save(user);
	}
	
<<<<<<< HEAD
	public User update(User user) {
		return userRepository.save(user);
	}
	
	public User selectById(String id) {
		return  userRepository.findById(id).get();
		
	}
	
	public void delete(String id) {
		 userRepository.deleteById(id);;
	}
=======
>>>>>>> f02232e15acf256ce9318fb7b78caf2ab4fad356
	
	public List<User> getAll() {
		return userRepository.findAll();
	}
	
	public User login(String name,String pwd) {
		return userRepository.findByNameAndPwd(name, pwd);
	}
	
	public List<User> likeName(String name) {
		return userRepository.findByNameLike(name+"%");
	}

}
